package p3.entity;

import p3.util.Tool;

import java.util.Date;
import java.util.Scanner;

public class Admin {
    private String name;
    private String password;

    public void showCost(ParkingArea area){
        for (int i=0;i<=area.getLots().length-1;i++){
            ParkingLot parkingLot=area.getLots()[i];
            if (parkingLot.getCar()!=null){
                Car car=parkingLot.getCar();
                int money= Tool.getParkingCost(Tool.getSecond(car.getStartTime(),new Date()));
                System.out.println("车位："+parkingLot.getLotNo()+"收入金额："+money);
            }
        }
    }

    public void show(ParkingArea area){
        for (int i=0;i<=area.getLots().length-1;i++){
            ParkingLot lot=area.getLots()[i];
            System.out.println(lot.getLotNo()+"\t"+((lot.getCar()==null)?"当前车位为空":lot.getCar().getCarNo()));

        }
    }

    public boolean login(ParkingArea area){
        Scanner scanner=new Scanner(System.in);
        System.out.println("账号：");
        String name=scanner.next();
        System.out.println("密码：");
        String pass=scanner.next();
        for (int i=0;i<=area.getAdmins().length-1;i++){
            Admin admin=area.getAdmins()[i];
            if (admin.getName().equals(name)&&admin.getPassword().equals(pass)){
                return true;
            }
        }
        return false;
    }


    public void register(ParkingArea area){
        boolean flag=false;
        int index=-1;
       for (int i=0;i<=area.getAdmins().length-1;i++){
           if (area.getAdmins()[i]==null){
               flag=true;
               index=i;
               break;
           }
       }
       if (flag){
           Scanner scanner=new Scanner(System.in);
           System.out.println("请输入注册账号：");
           name=scanner.next();
           System.out.println("请输入注册密码：");
           password=scanner.next();
           area.getAdmins()[index]=this;
           System.out.println("注册成功");
       }else {
           System.out.println("已有三个管理员，不允许注册");
       }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
